/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Deal.PersonalInformation.Logic;

import Data.DAO.ICustomerStore;
import data.pojo.Customer;
import java.util.List;
import java.util.Vector;

/**
 *
 * @author LiuBole
 */
public class BasicInformation {

    private ICustomerStore customerDS = new ICustomerStore();
    
    public String getUserName(String userId){ //通过顾客id获得name       
        List<Customer> arr = customerDS.searchObjectsByAttr("id", userId);
        if (arr.size() > 0) {
            return arr.get(0).getName();
        } else {
            return null;
        }
    }

    public boolean setCode(String user_id, String newCode) {
        List<Customer> cuList = (List<Customer>)customerDS.getObjects();
        for(Customer c : cuList){
            if(c.getName().equals(user_id)){
                c.setPaasword(newCode);
                break;
            }
        }
        customerDS.update(cuList);    
        return true;
    }

    public boolean addToPoint(int pI, String user_id) {
        List arr = customerDS.searchObjectsByAttr("id", user_id);
        Vector<Customer> seList = new Vector(arr);

        boolean succeed = true;
        for (int i = 0; i < seList.size(); i++) { //只有一个元素
            succeed = succeed & seList.get(i).addPoints(pI);
        }
        return succeed;
    }

    public int getUserPoints(String userId) {
        List<Customer> arr = customerDS.searchObjectsByAttr("id", userId);
        if (arr.size() > 0) {
            return arr.get(0).getPoints();
        } else {
            return -1;
        }

    }
//
//    public String getUserCode(String user_id) {
//        List arr = customerDS.searchObjectsByAttr("id", user_id);
//        Vector<Customer> seList = new Vector(arr);
//        if (seList.size() > 0) {
//            return seList.get(0).getPassword();
//        } else {
//            return null;
//        }
//
//    }
}
